﻿

namespace Mulala.Cavan.TestAppService.InformationModule
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using NUnit.Framework;
    using Spring.Context;
    using Spring.Context.Support;
    using Mulala.Cavan.Application.MainBoundedContext.InformationModule;
    using Mulala.Cavan.Application.MainBoundedContext.MulalaModule;
    using Mulala.Cavan.Domain.Seedwork;
    using Mulala.Cavan.Domain.MainBoundedContext.InformationModule;
    using Mulala.Cavan.Domain.MainBoundedContext.SecurityModule;
using Mulala.Cavan.Application.MainBoundedContext.SecurityModule;

    [TestFixture]
    public class TestNoteAppService
    {
        private IApplicationContext context;
        private INoteAppService NoteAppService { get; set; }
        private IUserAccountAppService UserAccountAppService { get; set; }

        [SetUp]
        public void SetUp()
        {
            context = ContextRegistry.GetContext();
            this.NoteAppService = context.GetObject(MulalaAppServiceConst.NOTEAPPSERVICE) as INoteAppService;
            this.UserAccountAppService = context.GetObject(MulalaAppServiceConst.USERACCOUNTAPPSERVICE) as IUserAccountAppService;
        }

        [Test]
        public void TestAdd()
        {
            BoolGenericResult<Note> result = new BoolGenericResult<Note>();
            Note note = new Note();
            note.SenderUserAccount = UserAccountFactory.CreateUserAccount(24, SecurityIdentifier.Role.Proprietor);
            note.Title = "test_note";
            note.Content = "test_note_content";
            note.NoteReceivers = new List<NoteReceiver>();
            NoteReceiver noteReceiver = NoteReceiverFactory.CreateNoteReceiver(UserAccountFactory.CreateUserAccount(33), false, true, "proprietor1");
            note.NoteReceivers.Add(noteReceiver);

            result = this.NoteAppService.Add(note);

            Assert.AreEqual(true, result.IsSuccess);
        }

        [Test]
        public void TestAddNoteReply()
        {
            BoolGenericResult<Note> result = new BoolGenericResult<Note>();
            Note noteToReply = this.NoteAppService.GetById(2);
            noteToReply.SenderUserAccount = this.UserAccountAppService.GetById(24);

            Note note = new Note();
            note.SenderUserAccount = UserAccountFactory.CreateUserAccount(33, SecurityIdentifier.Role.Nanny);
            note.Title = "Re:test_note";
            note.Content = "test_note_content";

            result = this.NoteAppService.AddNoteReply(noteToReply, note);

            Assert.AreEqual(true, result.IsSuccess);
        }
    }
}
